<!-- include tpl=head_lay -->
<script type="text/javascript">
function re_collection()
{
	var id = $.input.checkbox_join();
	if(!id){
		$.dialog.alert("请选择要执行的项目！");
		return false;
	}
	var url = get_url('plugin','exec','id=collection&exec=re_content&tid='+$.str.encode(id));
	$("#collection_status").html("正在执行初始化……");
	$.phpok.json(url,function(rs){
		if(rs.status == 'ok'){
			$("#collection_status").html("初始化完毕，请稍候，即将开始采集……");
			window.setTimeout("cj_content()",1000);
		}else{
			$("#collection_status").html(rs.content);
		}
	})
}
function cj_content()
{
	var id = $.input.checkbox_join();
	if(!id){
		$.dialog.alert("请选择要执行的项目！");
		return false;
	}
	var idlist = id.split(",");
	var start_count = $("#start_count").val();
	if(!idlist[start_count] || idlist[start_count] == "undefined"){
		$.dialog.alert("采集完成，请检查");
		$("#start_count").val(0);
		return true;
	}
	var tid = idlist[start_count];
	var cid = $("#cateid_"+tid).val();
	var url = get_url("plugin",'exec','id=collection&exec=content2&tid='+tid+"&cid="+cid);
	$.phpok.json(url,function(rs){
		if(rs.status == 'ok'){
			$("#collection_status").html(rs.content);
			var start_count = $("#start_count").val();
			$("#start_count").val((parseInt(start_count)+1));
			$("#status_"+tid).html("<span class='darkblue'>未发布</span>");
			window.setTimeout("cj_content()",1000);
		}else{
			$("#collection_status").html(rs.content);
		}
	});
}
function to_view(id)
{
	var url = get_url('plugin','exec','id=collection&exec=info_edit&lid='+id);
	$.dialog.open(url,{
		'title':'编辑数据',
		'width':'700px',
		'height':'400px',
		'lock':true,
		'ok':function(){
			var iframe = this.iframe.contentWindow;
			if (!iframe.document.body) {
				alert('iframe还没加载完毕呢');
				return false;
			};
			iframe.save();
			return false;
		},'okVal':'提交修改','cancelVal':'关闭','cancel':function(){}
	});
}
function to_del(id)
{
	var url = get_url('plugin','exec','id=collection&exec=info_delete&lid='+$.str.encode(id));
	$.phpok.json(url,function(rs){
		if(rs.status == 'ok'){
			$("#title_"+id).remove();
			$.dialog.tips('主题：'+id+' 删除成功');
		}else{
			$.dialog.alert(rs.content);
			return false;
		}
	});
}
function clear_post()
{
	var id = $.input.checkbox_join();
	if(!id){
		$.dialog.alert("请选择要执行的项目！");
		return false;
	}
	$.dialog.confirm('确定要取消该采集已发布的标记吗？<br />更新后，如执行采集入库，将会重新执行！',function(){
		var url = get_url('plugin','exec','id=collection&exec=clear_post&lid='+$.str.encode(id));
		$.phpok.json(url,function(rs){
			if(rs.status == 'ok'){
				$.phpok.reload();
			}else{
				$.dialog.alert(rs.content);
			}
		})
	});
}

function set_post()
{
	var id = $.input.checkbox_join();
	if(!id){
		$.dialog.alert("请选择要执行的项目！");
		return false;
	}
	$.dialog.confirm('确定要设置采集已发布的标记？<br />更新后，如执行采集入库，将会跳过执行！',function(){
		var url = get_url('plugin','exec','id=collection&exec=clear_post2&lid='+$.str.encode(id));
		$.phpok.json(url,function(rs){
			if(rs.status == 'ok'){
				$.phpok.reload();
			}else{
				$.dialog.alert(rs.content);
			}
		})
	});
}
function to_del_selected()
{
	var id = $.input.checkbox_join();
	if(!id){
		$.dialog.alert("请选择要删除的项目！");
		return false;
	}
	var list = id.split(",");
	for(var i in list){
		to_del(list[i]);
	}
}
function cj_post()
{
	var id = $.input.checkbox_join();
	if(!id){
		$.dialog.alert("请选择要执行的项目！");
		return false;
	}
	$.dialog.confirm('确定要执行发布吗？在执行发布过程中，请不要关闭浏览器！',function(){
		var url = get_url('plugin','exec','id=collection&exec=post_save&lid='+id);
		$.phpok.go(url);
	});
}
function cj_preview(id)
{
	var url = get_plugin_url('collection','preview','tid='+id);
	$.win('预览_#'+id,url);
}
</script>
<input type="hidden" id="start_count" value="0" />
<div class="layui-card">
	<div class="layui-card-body">
		<table class="layui-table">
		<thead>
		<tr>
			<th width="20px">&nbsp;</th>
			<th>ID</th>
			<th width="60px">状态</th>
			<th>网址</th>
			<th>&nbsp;</th>
		</tr>
		</thead>
		<!-- loop from=$rslist key=$key value=$value id=$tmpid -->
		<tr id="title_{$value.id}">
			<td align='center'><input type="checkbox" value="{$value.id}" /></td>
			<td>{$value.id}</td>
			<input type="hidden" id="cateid_{$value.id}" value="{$value.cid}" />
			<td id="status_{$value.id}">
				<!-- if $value.status == 2 -->
				已发布
				<!-- elseif $value.status == 1 -->
				<span class="darkblue">未发布</span>
				<!-- else -->
				<span class="red">未采集</span>
				<!-- /if -->
			</td>
			<td><a href="{$value.url}" target="_blank">{$value.url}</a></td>
			<td align="center">
				<div class="layui-btn-group">
					<input type="button" value="{lang预览}" onclick="cj_preview('{$value.id}')" class="layui-btn layui-btn-normal layui-btn-sm" />
					<input type="button" value="{lang编辑}" onclick="to_view('{$value.id}')" class="layui-btn layui-btn-sm" />
					<input type="button" value="{lang删除}" onclick="to_del('{$value.id}')" class="layui-btn layui-btn-sm layui-btn-danger" />
				</div>
			</td>
		</tr>
		<!-- /loop -->
		</table>
		<div class="layui-btn-group">
			<input type="button" value="{lang全选}" onclick="$.input.checkbox_all()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang全不选}" onclick="$.input.checkbox_none()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang反选}" onclick="$.input.checkbox_anti()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang重新采集}" onclick="re_collection()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang发布}" onclick="cj_post()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang标记未发布}" onclick="clear_post()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang标记已发布}" onclick="set_post()" class="layui-btn layui-btn-sm" />
			<input type="button" value="{lang删除}" onclick="to_del_selected()" class="layui-btn layui-btn-sm layui-btn-danger" />
			<div class="layui-btn layui-btn-sm layui-btn-normal">执行进度：<span class="darkblue" id="collection_status"></span></div>
		</div>
		<div class="clear"></div>
		<div align="center"><!-- include tpl=pagelist --></div>
	</div>
</div>

<!-- include tpl=foot_lay -->